<?php
/**
 *
 * @package 
 * @since 1.0
 * @todo 登陆 注册
 */
class image {
        // 当前图片
        protected $img;
        // 图像types 对应表
        protected $types = array(
                        1 => 'gif',
                        2 => 'jpg',
                        3 => 'png',
                        6 => 'bmp'
                    );
        
        // image
        public function __construct($img=''){
                !$img && $this->param($img);
        }
        
        // Info
        public function param($img){
                $this->img = $img;
                return $this;
        }
        
        // imageInfo
        public function getImageInfo($img){
                $info = @getimagesize($img);
                if(isset($this->types[$info[2]])){
                        $info['ext'] = $info['type'] = $this->types[$info[2]];
                } else{
                        $info['ext'] = $info['type'] = 'jpg';
                }
                $info['type'] == 'jpg' && $info['type'] = 'jpeg';
                $info['size'] = @filesize($img);
                return $info;
        }
        
        // thumb(新图地址, 宽, 高, 裁剪, 允许放大)
        public function thumb($filename,$new_w,$new_h,$cut=0,$big=0){
        // 获取原图信息   
        $info  = $this->getImageInfo($this->img);
        if(!empty($info[0])) {
            $old_w  = $info[0];
            $old_h  = $info[1];
            $type   = $info['type'];
            $ext    = $info['ext'];
            unset($info);
            // 如果原图比缩略图小 并且不允许放大
            if($old_w < $new_h && $old_h < $new_w && !$big){
                    return false;
            }
            // 裁剪图片
            if($cut == 0){ // 等比列
                    $scale = min($new_w/$old_w, $new_h/$old_h); // 计算缩放比例
                    $width  = (int)($old_w*$scale); // 缩略图尺寸
                    $height = (int)($old_h*$scale);
                    $start_w = $start_h = 0;
                    $end_w = $old_w;
                    $end_h = $old_h;
            } elseif($cut == 1){ // center center 裁剪
                        $scale1 = round($new_w/$new_h,2);
                        $scale2 = round($old_w/$old_h,2);
                        if($scale1 > $scale2){
                                $end_h = round($old_w/$scale1,2);
                                $start_h = ($old_h-$end_h)/2;
                                $start_w  = 0;
                                $end_w    = $old_w;
                        } else{
                                $end_w  = round($old_h*$scale1,2);
                                $start_w  = ($old_w-$end_w)/2;
                                $start_h = 0;
                                $end_h   = $old_h;
                        }
                        $width = $new_w;
                    $height= $new_h; 
                } elseif($cut == 2){ // left top 裁剪           
                        $scale1 = round($new_w/$new_h,2);
                    $scale2 = round($old_w/$old_h,2);
                    if($scale1 > $scale2){
                            $end_h = round($old_w/$scale1,2);
                            $end_w = $old_w;
                    } else{
                            $end_w = round($old_h*$scale1,2);
                            $end_h = $old_h;
                    }
                    $start_w = 0;
                    $start_h = 0;
                    $width = $new_w;
                    $height= $new_h; 
                }
            // 载入原图
            $createFun  = 'ImageCreateFrom'.$type;
            $oldimg     = $createFun($this->img); 
            // 创建缩略图
            if($type!='gif' && function_exists('imagecreatetruecolor')){
                $newimg = imagecreatetruecolor($width, $height); 
            } else{
                $newimg = imagecreate($width, $height); 
            }
            // 复制图片
            if(function_exists("ImageCopyResampled")){
                    ImageCopyResampled($newimg, $oldimg, 0, 0, $start_w, $start_h, $width, $height, $end_w,$end_h); 
            } else{
                ImageCopyResized($newimg, $oldimg, 0, 0, $start_w, $start_h, $width, $height, $end_w,$end_h);
            } 

            // 对jpeg图形设置隔行扫描
            $type == 'jpeg' && imageinterlace($newimg,1);
            // 生成图片
            $imageFun = 'image'.$type;
            !@$imageFun($newimg,$filename) && die('保存失败!检查目录是否存在并且可写!');
            ImageDestroy($newimg);
            ImageDestroy($oldimg);
            return $filename;
        }
        return false;
    }
    
    // water(保存地址,水印图片,水印位置,透明度)
        public function water($filename,$water,$pos=9,$pct=100){
                // 加载水印图片
                $info = $this->getImageInfo($water);
                if(!empty($info[0])){
                        $water_w = $info[0];
                        $water_h = $info[1];
                        //$water_wj = $info[0];
                       // $water_hj = $info[1];
                        $type = $info['type'];
                        $fun  = 'imagecreatefrom'.$type;
                        //$waterimgj = $fun($water);
                        $waterimg = $fun($water);
                } else{
                        return false;
                }
                // 加载背景图片
                $info = $this->getImageInfo($this->img);
                if(!empty($info[0])){
                        $old_w = $info[0];
                        $old_h = $info[1];
                        $type  = $info['type'];
                        $fun   = 'imagecreatefrom'.$type;
                        $oldimg = $fun($this->img);
                } else{
                        return false;
                }
                // 剪切水印
                //$water_w >$old_w && $water_w = $old_w;
                //$water_h >$old_h && $water_h = $old_h;
				
                //$water_w = (int)(0.2*$old_w);
				//$bilizhi=$water_w/$water_wj;
				//$water_h = (int)($bilizhi*$water_hj);

				//$waterimg = imagecreatetruecolor($water_w, $water_h); 
				//$waterimg = imagecreate($water_w, $water_h); 
				//$wt_background_color = imagecolorallocate($waterimg, 0,0,0); 
				//imagecolortransparent($waterimg,$wt_background_color);
//				$wt_white = imagecolorallocate($waterimg, 255, 255, 255);
//				imagechar($waterimg,2,0,0,"CHINA SPOSA.com",$wt_white);
				//imagecopyresized($waterimg,$waterimgj,0,0,0,0,$water_w,$water_h,$water_wj,$water_hj);
				
				//$waterimg =$waterimgj;
				//$water_w=$water_wj;
				//$water_h=$water_hj;
				
                // 水印位置                        
                switch($pos){
                        case 0://随机 
                    $posX = rand(0,($old_w - $water_w)); 
                    $posY = rand(0,($old_h - $water_h)); 
                    break; 
                case 1://1为顶端居左 
                    $posX = 0; 
                    $posY = 0; 
                    break; 
                case 2://2为顶端居中 
                    $posX = ($old_w - $water_w) / 2; 
                    $posY = 0; 
                    break; 
                case 3://3为顶端居右 
                    $posX = $old_w - $water_w; 
                    $posY = 0; 
                    break; 
                case 4://4为中部居左 
                    $posX = 0; 
                    $posY = ($old_h - $water_h) / 2; 
                    break; 
                case 5://5为中部居中 
                    $posX = ($old_w - $water_w) / 2; 
                    $posY = ($old_h - $water_h) / 2; 
                    break; 
                case 6://6为中部居右 
                    $posX = $old_w - $water_w; 
                    $posY = ($old_h - $water_h) / 2; 
                    break; 
                case 7://7为底端居左 
                    $posX = 0; 
                    $posY = $old_h - $water_h; 
                    break; 
                case 8://8为底端居中 
                    $posX = ($old_w - $water_w) / 2; 
                    $posY = $old_h - $water_h; 
                    break; 
                case 9://9为底端居右 
                    $posX = $old_w - $water_w; 
                    $posY = $old_h - $water_h; 
                    break; 
                default: //随机 
                    $posX = rand(0,($old_w - $water_w)); 
                    $posY = rand(0,($old_h - $water_h)); 
                    break;   
                }
            // 设定图像的混色模式 
                imagealphablending($oldimg, true); 
                // 添加水印
                imagecopymerge($oldimg, $waterimg, $posX, $posY, 0, 0, $water_w,$water_h,$pct);
                $fun = 'image'.$type;
                !@$fun($oldimg, $filename) && die('保存失败!检查目录是否存在并且可写?'); 
                  imagedestroy($oldimg);
                  imagedestroy($waterimg);
                  return $filename;        
        }
}
 
class UserAction extends AllAction{

	/**
	 * ------------------------------
	 * 权限判断
	 * ------------------------------
	 */
	function pan_quan_ajax($data){  //ajax判断
		$pan=in_array($data,$_SESSION['admin_quan']);
        if($pan){
			return true;
		}else{
			return false;
		}
	}
	function pan_quan($data){ //php跳转判断
		$pan=in_array($data,$_SESSION['admin_quan']);
        if(!$pan){
			$this->assign('jumpUrl', U('User/login'));
			$this->error('请先登录');
		}
	}
	
//	function check_user_name(){
//		$adm_name=$_POST['adm_name'];
//		if(M('admin')->where("adm_name='$adm_name'")->find()){
//			echo "1";
//		}else{
//			echo "0";
//		}
//		exit;
//	}
//	function check_nicheng(){
//		$nicheng=$_POST['nicheng'];
//		if(M('admin')->where("nicheng='$nicheng'")->find()){
//			echo "1";
//		}else{
//			echo "0";
//		}
//		exit;
//	}
//	function check_vcode(){
//		$vcode=$_POST['vcode'];
//		if(strtolower($vcode)!=strtolower($_SESSION['vcode'])){
//			echo "1";
//		}else{
//			echo "0";
//		}
//		exit;
//	}
//

    /**
     +----------------------------------------------------------
     * 登录
     +----------------------------------------------------------
    */
    public function login(){
		if(empty($_COOKIE['ly_url'])){
			if(!empty($_SERVER['HTTP_REFERER'])){
				$ly_url=$_SERVER['HTTP_REFERER'];
			}else{
				$ly_url="./index.php";
			}
			setcookie('ly_url',$ly_url);
		}
		if($_SESSION['id']){
			$this->assign('jumpUrl',U('User/mycenter'));
			$this->error("已登录！");
		}else{
			$this->assign('pagetitle', '欢迎登录');
			$this->display();
		}
    }
    /**
     +----------------------------------------------------------
     * 邮箱登录
     +----------------------------------------------------------
    */
    public function loginemail(){
		
		if($_SESSION['id']){
			$this->assign('jumpUrl',U('User/mycenter'));
			$this->error("已登录！");
		}else{
			$this->assign('pagetitle', '欢迎登录');
			$this->display();
		}
    }
    /**
     +----------------------------------------------------------
     * 注册
     +----------------------------------------------------------
    */
    public function reg(){
		if(empty($_COOKIE['ly_url'])){
			if(!empty($_SERVER['HTTP_REFERER'])){
				$ly_url=$_SERVER['HTTP_REFERER'];
			}else{
				$ly_url="./index.php";
			}
			setcookie('ly_url',$ly_url);
		}
		
		if($_SESSION['id']){
			$this->assign('jumpUrl',U('User/mycenter'));
			$this->error("已登录！");
		}else{
			$this->assign('pagetitle', '欢迎注册');
			$this->display();
		}
    }
    

    /*验证码	---index/login*/
    public function vdcode(){
    	$type	 =	 isset($_GET['type'])?$_GET['type']:'gif';
        import("ORG.Util.Image");
        Image::buildImageVerify(5,1,$type);
    }
    
    public function cheklogin(){
    	if(''==$_POST['tel']){
    		$this->error('手机为空！');
    	}elseif (''==$_POST['pass']){
    		$this->error('密码为空！');
    	}
//		elseif (''==$_POST['vdcode']){
//    		$this->error('验证码为空！');
//    	}
		elseif (!M()->autoCheckToken($_POST)){
    		$this->error('禁止外部提交！');
    	}
//		elseif ($_SESSION['verify'] != md5($_POST['vdcode'])){
//    		$this->error('验证码错！');
//    	}
		else {
    		
    		//$map['adm_name'] = t(h($_POST['adm_name']));
    		//$map['adm_name'] = t(h($_POST['tel']));
    		$maps['tel'] = t(h($_POST['tel']));
    		//$res = M('user')->where("tel=".$maps['tel']." or adm_name=".$map['adm_name']."")->find();
    		$res = M('user')->where("tel=".$maps['tel']."")->find();
    		//var_dump($res);exit;
    		if($res){
    			
    			if( $res['passwd'] == md5($_POST['pass'])){
					if($res['state']==1){
						//LOG
						//$datalog = "用户 {$_SESSION['adm_name']} 于".date('Y-m-d H:i:s', time())."成功登录系统！";
						//ALOG(1, $datalog);
						
//						$admin_ltime['uid']=$res['id'];
//						$admin_ltime['ctime']=time();
//						$admin_ltime['state']=1;
//						M('admin_ltime')->add($admin_ltime);
						//header('P3P: CP="CURa ADMa DEVa PSAo PSDo OUR BUS UNI PUR INT DEM STA PRE COM NAV OTC NOI DSP COR"');
						
						
						$_SESSION=$res;
						//$this->assign('waitSecond', 0);
						$this->assign('jumpUrl', U('User/mycenter'));
						$this->success("{$_SESSION['nicheng']}登录成功！");

					}else{
						if($res['state']==0){
							$this->error("此用户尚未激活！");
						}
						if($res['state']==3){
							$this->error("此用户已删除！");
						}
					}
    			}else {
//     				echo $res['passwd']; die;
    				$this->error("密码错误！");
    			}
    			
    		}else {
    			$this->error("无此用户！");
    		}
    	}
    }
    public function chekloginemail(){
    	if(''==$_POST['adm_name']){
    		$this->error('邮箱为空！');
    	}elseif (''==$_POST['pass']){
    		$this->error('密码为空！');
    	}elseif (''==$_POST['vdcode']){
    		$this->error('验证码为空！');
    	}elseif (!M()->autoCheckToken($_POST)){
    		$this->error('禁止外部提交！');
    	}elseif ($_SESSION['verify'] != md5($_POST['vdcode'])){
    		$this->error('验证码错！');
    	}else {
    		
    		$map['adm_name'] = t(h($_POST['adm_name']));
    		$res = M('admin')->where("adm_name=".$maps['adm_name']."")->find();
    		
    		if($res){
    			
    			if( $res['passwd'] == md5($_POST['pass'])){
					if($res['groupid']!=6){
						$this->error("只有会员可在此登录！");
					}
					if($res['state']==1){
						//LOG
						//$datalog = "用户 {$_SESSION['adm_name']} 于".date('Y-m-d H:i:s', time())."成功登录系统！";
						//ALOG(1, $datalog);
						
						$admin_ltime['uid']=$res['id'];
						$admin_ltime['ctime']=time();
						$admin_ltime['state']=1;
						M('admin_ltime')->add($admin_ltime);
						
						//setcookie('id', $res['id'], time()+60*60*24);
						$_SESSION=$res;

						$this->assign('waitSecond', 0);
						$this->assign('jumpUrl', $_COOKIE['ly_url']);
						$this->success("{$_SESSION['nicheng']}登录成功！");
					}else{
						if($res['state']==0){
							$this->error("此用户尚未激活！");
						}
						if($res['state']==3){
							$this->error("此用户已删除！");
						}
					}
    			}else {
//     				echo $res['passwd']; die;
    				$this->error("密码错误！");
    			}
    			
    		}else {
    			$this->error("无此用户！");
    		}
    	}
    }
    public function chekreg(){
//    	if(''==$_POST['adm_name']){
//    		$this->error('邮箱为空！');
//    	}elseif (''==$_POST['nicheng']){
    	if(''==$_POST['tel']){
    		$this->error('手机号为空！');
    	}elseif (''==$_POST['nicheng']){
    		$this->error('昵称为空！');
    	}elseif (''==$_POST['pass']){
    		$this->error('密码为空！');
    	}elseif ($_POST['pass2']!=$_POST['pass']){
    		$this->error('两次密码不一致！');
    	}elseif (!M()->autoCheckToken($_POST)){
    		$this->error('禁止外部提交！');
    	}else {
    		
    		//$map['adm_name'] = t(h($_POST['adm_name']));
    		$map['tel'] = t(h($_POST['tel']));
    		$res = M('admin')->where($map)->find();
    		
    		if($res){
    			//$this->error("此邮箱已注册！");
    			$this->error("此手机号已注册！");
    			    			
    		}else {

				//if($_POST['dxyzm']==$_SESSION['dxyzm_ys'] && $map['tel']==$_SESSION['tel_ys']){
//				echo $_POST['dxyzm']."<br>";
//				echo $_COOKIE['dxyzm_ys']."<br>";
//				echo $map['tel']."<br>";
//				echo $_COOKIE['tel_ys']."<br>";
//				exit;
				if($_POST['dxyzm']==$_COOKIE['dxyzm_ys'] && $map['tel']==$_COOKIE['tel_ys']){
					$reg['passwd'] = md5($_POST['pass']);
					$reg['state']=1;
					$reg['groupid']=6;
					$reg['ctime']=time();
					//$reg['adm_name'] = $map['adm_name'];
					$reg['tel'] = $map['tel'];
					$reg['nicheng'] = t(h($_POST['nicheng']));
					$reg['dxyzm'] = $_POST['dxyzm'];
					//邮箱验证激活
					//$reg['jihuoma'] = md5($map['adm_name'].$reg['ctime']);
					//$reg['jihuoma_exptime'] = $reg['ctime']+60*60*24;
					
					
					$reg_add=M('admin')->add($reg);
	
					if( $reg_add ){
						//发送验证邮件
	//					$ver=$reg['jihuoma'];
	//					$ll="http://mxingtv.com/index.php?a=jihuo&m=User&ket=".$ver."&id=".$reg_add;
	//					sendemail($map['adm_name'], '萌星网', $map['adm_name'], "您好，".$map['adm_name']."  复制下面地址,到浏览器中打开\r\n".$ll."\r\n"."此邮件是验证邮件，不必回复。","会员注册激活");
						
						//短信验证码
						//$reg['dxyzm'] = rand(000000,999999);
						//发送短信验证码
	//					$dxyam_url="http://106.3.37.122:9999/sms.aspx?action=send&userid=913&account=kubang&password=abc123&mobile=".$reg['tel']."&content=尊敬的会员您好，您目前正在进行注册操作,验证码为".$reg['dxyzm']."，如非本人操作请联系管理员【萌星网】";
	//					$dxyam_result = file_get_contents($dxyam_url); 
						
						//var_dump($dxyam_result);exit;
						$admin_ltime['uid']=$reg_add;
						$admin_ltime['ctime']=time();
						$admin_ltime['state']=1;
						M('admin_ltime')->add($admin_ltime);
						
						//setcookie('id', $res['id'], time()+60*60*24);
						$_SESSION=$reg;
						$_SESSION['id']=$reg_add;
	
						//$this->assign('waitSecond', 1);
						$this->assign('jumpUrl', $_COOKIE['ly_url']);
						$this->success("注册成功！");
						//$this->success("欢迎:{$_SESSION['adm_name']}！请及时登录到您的邮箱激活您的帐号！");
						
					}else {
						$this->error("注册失败！");
					}
				}else{
					$this->error("手机验证码错误！");
				}
    		}
    	}
    }
	//注册 发送验证码
	function fs_dxyzm(){
		$tel=t(h($_POST['tel']));
						
		//短信验证码
		$dxyzm = rand(100000,999999);
		setcookie("tel_ys",$tel,time()+90);
		setcookie("dxyzm_ys",$dxyzm,time()+90);
		//$_SESSION['tel_ys']=$tel;
		//$_SESSION['dxyzm_ys']=$dxyzm;

		//发送短信验证码
		$dxyam_url="http://106.3.37.122:9999/sms.aspx?action=send&userid=913&account=kubang&password=abc123&mobile=".$tel."&content=尊敬的会员您好，您目前正在进行注册操作,验证码为".$dxyzm.",如非本人操作请联系管理员【萌星网】";
		$dxyam_result = file_get_contents($dxyam_url); 
		
		echo "1";
		exit;
//		if(){
//			echo "1";
//		}else{
//			echo "0";
//		}
//		exit;
	}
	//找回密码 发送验证码
	function fs_dxyzm_gai(){
		$tel=t(h($_POST['tel']));
						
		//短信验证码
		$dxyzm = rand(100000,999999);
		setcookie("tel_ys",$tel,time()+500);
		setcookie("dxyzm_ys",$dxyzm,time()+500);

		//发送短信验证码
		$dxyam_url="http://106.3.37.122:9999/sms.aspx?action=send&userid=913&account=kubang&password=abc123&mobile=".$tel."&content=尊敬的会员您好，您目前正在进行找回密码操作,验证码为".$dxyzm.",如非本人操作请联系管理员【萌星网】";
		$dxyam_result = file_get_contents($dxyam_url); 
		
		echo "1";
		exit;
	}

    public function chekregemail(){
    	if(''==$_POST['adm_name']){
    		$this->error('邮箱为空！');
    	}elseif (''==$_POST['nicheng']){
    		$this->error('昵称为空！');
    	}elseif (''==$_POST['pass']){
    		$this->error('密码为空！');
    	}elseif ($_POST['pass2']!=$_POST['pass']){
    		$this->error('两次密码不一致！');
    	}elseif (''==$_POST['vdcode']){
    		$this->error('验证码为空！');
    	}elseif (!M()->autoCheckToken($_POST)){
    		$this->error('禁止外部提交！');
    	}elseif ($_SESSION['verify'] != md5($_POST['vdcode'])){
    		$this->error('验证码错！');
    	}else {
    		
    		$map['adm_name'] = t(h($_POST['adm_name']));
    		$res = M('admin')->where($map)->find();
    		
    		if($res){
    			$this->error("此邮箱已注册！");
    			    			
    		}else {
			
				$reg['passwd'] = md5($_POST['pass']);
				$reg['state']=0;
				$reg['groupid']=6;
				$reg['ctime']=time();
				$reg['adm_name'] = $map['adm_name'];
				$reg['nicheng'] = t(h($_POST['nicheng']));
				//邮箱验证激活
				$reg['jihuoma'] = md5($map['adm_name'].$reg['ctime']);
				$reg['jihuoma_exptime'] = $reg['ctime']+60*60*24;
				
				$reg_add=M('admin')->add($reg);

    			if( $reg_add ){
					//发送验证邮件
					$ver=$reg['jihuoma'];
					$ll="http://mxingtv.com/index.php?a=jihuo&m=User&ket=".$ver."&id=".$reg_add;
					sendemail($map['adm_name'], '萌星网', $map['adm_name'], "您好，".$map['adm_name']."  复制下面地址,到浏览器中打开\r\n".$ll."\r\n"."此邮件是验证邮件，不必回复。","会员注册激活");
					
					$admin_ltime['uid']=$reg_add;
					$admin_ltime['ctime']=time();
					$admin_ltime['state']=1;
					M('admin_ltime')->add($admin_ltime);
					
					//setcookie('id', $res['id'], time()+60*60*24);
					$_SESSION=$reg;
					$_SESSION['id']=$reg_add;
					
					$this->assign('waitSecond', 3);
					$this->assign('jumpUrl', $_COOKIE['ly_url']);
					$this->success("欢迎:{$_SESSION['adm_name']}！请及时登录到您的邮箱激活您的帐号！");
					
    			}else {
    				$this->error("注册失败！");
    			}

    		}
    	}
    }
	function jihuo(){
		$verify = $_GET['ket'];
		$id=$_GET['id']; 
		 
		$row = M('admin')->where("jihuoma='$verify' and id='$id'")->find(); 
		if($row){ 
			$row['state']=1; 
			if(M('admin')->save($row)){
				$this->assign('jumpUrl', './index.php');
				$this->success("恭喜您，激活成功！");
			}else{
				$this->assign('jumpUrl', './index.php');
				$this->success("已经激活！");
			}
		}else{ 
			$msg = 'error.';     
		} 
		echo $msg;
	}
    
    public function logout(){
    	import("ORG.Util.Session");
		$s = new Session();
		$s->destroy();
		
		//setcookie("id", 0, time());
		//setcookie("id", 0, time(),"/","mxingtv.com",0);
		$this->assign('jumpUrl', './index.php');
		$this->success("已退出！");
    }
    
	function check_email($email) {
       $pattern_test = "/([a-z0-9]*[-_.]?[a-z0-9]+)*@([a-z0-9]*[-_]?[a-z0-9]+)+[.][a-z]{2,3}([.][a-z]{2})?/i";
       return  preg_match($pattern_test,$email);
    }    
	
	function check_user_name(){
		$user_name=$_POST['user_name'];
		if(M('admin')->where("adm_name='$user_name'")->find()){
			echo "1";
		}else{
			echo "0";
		}
		exit;
	}
	function check_tel(){
		$tel=$_POST['tel'];
		if(M('admin')->where("tel='$tel'")->find()){
			echo "1";
		}else{
			echo "0";
		}
		exit;
	}
	function check_nicheng(){
		$nicheng=$_POST['nicheng'];
		if(M('admin')->where("nicheng='$nicheng' and id!=".$_SESSION['uid']."")->find()){
			echo "1";
		}else{
			echo "0";
		}
		exit;
	}
	function check_vdcode(){
		$vdcode=$_POST['vdcode'];
		if(md5($vdcode)!=$_SESSION['verify']){
			//echo $_SESSION['vcode'];
			echo "1";
		}else{
			echo "0";
		}
		exit;
	}
    //找回密码
    public function zhmm(){
	
		$this->display();
	}
    public function zhmm_check(){
    	if(''==$_POST['tel']){
    		$this->error('手机号为空！');
    	}elseif (!M()->autoCheckToken($_POST)){
    		$this->error('禁止外部提交！');
    	}else {
    		
    		$map['tel'] = t(h($_POST['tel']));
    		$res = M('admin')->where("tel=".$map['tel']."")->find();
    		
    		if(!$res){
    			$this->error("此手机号未注册！");
    			    			
    		}else {

				if($_POST['dxyzm']==$_COOKIE['dxyzm_ys'] && $map['tel']==$_COOKIE['tel_ys']){
					
					$this->assign("jumpUrl", "./index.php?a=zhmm_gai&m=user&dxyzm=".$_POST['dxyzm']."&tel=".$map['tel']."");
					$this->success("手机验证成功！");
				}else{
					$this->error("手机验证失败！");
				}
    		}
    	}
    }
    //找回密码
    public function zhmm_gai(){
    	if(''==$_GET['tel']){
    		$this->error('手机号为空！');
    	}elseif (''==$_GET['dxyzm']){
    		$this->error('短信验证码为空！');
    	}else {
    		
    		$map['tel'] = t(h($_GET['tel']));
    		$res = M('admin')->where("tel=".$map['tel']."")->find();
    		
    		if(!$res){
    			$this->error("此手机号未注册！");
    			    			
    		}else {

				if($_GET['dxyzm']==$_COOKIE['dxyzm_ys'] && $map['tel']==$_COOKIE['tel_ys']){
					$_SESSION['tel'] = $map['tel'];
					$_SESSION['dxyzm'] = $_GET['dxyzm'];
					$this->display();
				}else{
					$this->error("手机验证超时！");
				}
    		}
    	}
    }
    //找回密码
    public function zhmm_gai_check(){
    	if(''==$_SESSION['tel']){
    		$this->error('手机号为空！');
    	}elseif (''==$_POST['pass']){
    		$this->error('密码为空！');
    	}elseif ($_POST['pass2']!=$_POST['pass']){
    		$this->error('两次密码不一致！');
    	}elseif (!M()->autoCheckToken($_POST)){
    		$this->error('禁止外部提交！');
    	}else {
    		
    		$map['tel'] = $_SESSION['tel'];
    		$res = M('admin')->where("tel=".$map['tel']."")->find();
    		
    		if(!$res){
    			$this->error("此手机号未注册！");
    			    			
    		}else {

				if($_SESSION['dxyzm']==$_COOKIE['dxyzm_ys'] && $map['tel']==$_COOKIE['tel_ys']){
					$res['passwd'] = md5($_POST['pass']);
					$res['state']=1;					
					
					$res_save=M('admin')->save($res);
	
					if( $res_save ){
						$_SESSION['tel']="";
						$_SESSION['dxyzm']="";
						setcookie("tel_ys","",time()-500);
						setcookie("dxyzm_ys","",time()-500);
						$this->assign('jumpUrl', U('User/login'));
						$this->success("修改成功！");
						
					}else {
						$this->error("修改失败！");
					}
				}else{
					$this->error("手机验证超时！");
				}
    		}
    	}
    }
	function zhmmemail(){
	
		$this->display();  
	  
	}
	function zhmmemail_do(){
		$user_name=$_POST['adm_name'];
		$user=M('admin')->where("adm_name='$user_name'")->find();
		if($user['id']==""){
			$this->error("此邮箱尚未注册");	exit;
		}			
		if ($_SESSION['verify'] != md5($_POST['vdcode'])){
			$this->error('验证码错！');	exit;
    	}
//		$yanzheng=strtolower($_POST["vdcode"]);
//		$aa=strtolower($_SESSION['verify']);
//		if($aa!=$yanzheng){
//			$this->error("验证码错误");	exit;
//		}
		
		$ll=rand(10000000, 99999999).$user['id'];
		$user['passwd']=md5($ll);
		M('admin')->save($user);
		sendemail($user['adm_name'], '萌星网', $user['adm_name'], "您好，".$user['nicheng']."  您的密码已修改为:\r\n".$ll."\r\n"."此邮件是找回密码邮件，不必回复。","会员密码找回");
		
		$this->assign('jumpUrl', $_COOKIE['ly_url']);
		$this->success("恭喜您，提交成功！请登录到您的邮箱查看新密码！");
	
	}
	  
	function mycenter(){
		//var_dump(ACTION_NAME);
		$id=$_SESSION['id'];
		if($id>0){
			$user=M("user")->where("state=1 and id=".$id."")->find();
			$this->assign('user', $user);
			$guanzhushu=M("user_fensi")->where("state=1 and uid=".$id."")->count();
			$this->assign('guanzhushu', $guanzhushu);
			$sf_yi_baoming=M("user_baoming")->where("uid=".$uid." and state=1")->find();
			$this->assign('sf_yi_baoming', $sf_yi_baoming);
		}
		$this->display();  
	  
	}
	  
	function mycenter_info(){
		$uid=$_SESSION['id'];
		if(empty($uid)){
			$this->error('请先登录');
		}
		//$webid=$this->get_webid();
		//$show_uid=$_GET['suid'];
		
		$user_show=M('user')->where("id=".$uid."")->find();
		$this->assign('user_show',$user_show);
		
		$user_show_info=M('user_info')->where("uid=".$uid."")->find();
		$this->assign('user_show_info',$user_show_info);
		$photo_file=M("article_photo_files")->where("suid=".$uid." and state=1")->find();
		$user_photo=M('article_photo')->where("suid=".$uid." and fid=".$photo_file['id']." and state=1")->select();
		$this->assign('user_photo',$user_photo);
		
		$this->display();  
	  
	}
	function mycenter_infodo(){
	
		if(''==$_POST['name']){
    		$this->error('请填写姓名！');
    	}elseif (''==$_POST['yiming']){
    		$this->error('请填写艺名！');
    	}elseif (''==$_POST['sex']){
    		$this->error('请选择性别！');
    	}elseif (''==$_POST['year'] || ''==$_POST['month'] || ''==$_POST['day']){
    		$this->error('请选择出生日期！');
    	}elseif (''==$_POST['minzu']){
    		$this->error('请填写民族！');
    	}elseif (''==$_POST['shengao']){
    		$this->error('请填写身高！');
    	}elseif (''==$_POST['tizhong']){
    		$this->error('请填写体重！');
    	}elseif (''==$_POST['xingzuo']){
    		$this->error('请选择星座！');
    	}elseif (''==$_POST['yuyan']){
    		$this->error('请填写语言！');
    	}elseif (''==$_POST['home']){
    		$this->error('请填写籍贯！');
    	}elseif (''==$_POST['area']){
    		$this->error('请填写现居住地！');
    	}elseif (''==$_POST['email']){
    		$this->error('请填写邮箱！');
    	}elseif (''==$_POST['tel']){
    		$this->error('请填写手机号！');
    	}elseif (''==$_POST['xingqu']){
    		$this->error('请填写特长爱好！');
    	}elseif (''==$_POST['jianjie']){
    		$this->error('请填写主播宣言！');
    	}else {
			
			if(empty($_SESSION['id'])){
				$this->error('请先登录！');
			}
			$uid=$_SESSION['id'];
    		
			$user_show['id']=$uid;
			$user_show['name']=t(h($_POST['name']));
			$user_show['email']=t(h($_POST['email']));
			$user_show['tel']=t(h($_POST['tel']));
			
			$user_show_info['uid']=$uid;
			$user_show_info['yiming']=t(h($_POST['yiming']));
			$user_show_info['sex']=t(h($_POST['sex']));
			$user_show_info['year']=t(h($_POST['year']));
			$user_show_info['month']=t(h($_POST['month']));
			$user_show_info['day']=t(h($_POST['day']));
			$user_show_info['minzu']=t(h($_POST['minzu']));
			$user_show_info['shengao']=t(h($_POST['shengao']));
			$user_show_info['tizhong']=t(h($_POST['tizhong']));
			$user_show_info['xingzuo']=t(h($_POST['xingzuo']));
			$user_show_info['yuyan']=t(h($_POST['yuyan']));
			$user_show_info['home']=t(h($_POST['home']));
			$user_show_info['area']=t(h($_POST['area']));
			$user_show_info['xingqu']=t(h($_POST['xingqu']));
			$user_show_info['jianjie']=t(h($_POST['jianjie']));
			$user_show_info['peixun']=t(h($_POST['peixun']));
			$user_show_info['guhua']=t(h($_POST['guhua']));
			$user_show_info['ctime']=time();
			$user_show_info['state']=1;
			
			M("user")->save($user_show);
			
			$user_show_info_jiu=M("user_info")->where("uid=".$uid."")->find();
			if(empty($user_show_info_jiu)){
				M("user_info")->add($user_show_info);
			}else{
				$user_show_info['id']=$user_show_info_jiu['id'];
				M("user_info")->save($user_show_info);
			}

			$folder="/data/baomingxiezhen/";
			for ($i=0;$i<count($_FILES);$i++) 
			{ 
				if(!empty($_FILES[$i]['name'])){
					$picname = $_FILES[$i]['name'];
					$picsize = $_FILES[$i]['size'];
					if ($picname != "") {
						if ($picsize > 2048000) {
							echo '图片大小不能超过2M';
							exit;
						}
						$type = strstr($picname, '.');
						if ( $type != ".jpg") {
							echo '图片格式不对！';
							exit;
						}
						$rand = rand(1000, 9999);
						$pics = date("YmdHis",time()) . "_".$rand . $type;
						//上传路径
						$targetPath = $_SERVER['DOCUMENT_ROOT'] . $folder;
						$pic_path =  str_replace('//','/',$targetPath) . $pics;
						//mkdir(str_replace('//','/',$targetPath), 0755, true);
						if(!is_dir(str_replace('//','/',$targetPath))){
							mkdir(str_replace('//','/',$targetPath), 0755, true); //创建 目录
						}
				
						move_uploaded_file($_FILES[$i]['tmp_name'], $pic_path);
					}
					$size = round($picsize/2048,2);
					$arr[$i] = array(
						'name'=>$picname,
						'pic'=>$pics,
						'pic_path'=>$folder.$pics,
						'size'=>$size
					);
					
					$photo['name']="写真照".($i+1);
					$photo['url']=$folder.$pics;
					$photo['state']=1;
					$photo['ctime']=time();
					$photo['suid']=$uid;
					$photo['uid']=$uid;
						
					$photo_file=M("article_photo_files")->where("suid=".$uid." and state=1")->find();
					if(!empty($photo_file)){
						$photo['fid']=$photo_file['id'];
						M("article_photo")->add($photo);
					}else{
						$new_photo_file['uid']=$uid;
						$new_photo_file['suid']=$uid;
						$new_photo_file['state']=1;
						$new_photo_file['ctime']=time();
						$new_photo_file['name']="写真集";
						$new_photo_file['url']=$folder.$pics;
						$new_files=M("article_photo_files")->add($new_photo_file);
						
						$photo['fid']=$new_files;
						M("article_photo")->add($photo);
					}
				}
			} 
			$photo_file_jiu=M("article_photo_files")->where("suid=".$uid." and state=1")->find();
			$photo_jiu=M("article_photo")->where("suid=".$uid." and fid=".$photo_file_jiu['id']." and state=1")->select();
			if(count($arr)<2 && count($photo_jiu)==0){
				$this->error('照片最少两张！');
			}
			if(count($arr)<1 && count($photo_jiu)==1){
				$this->error('照片最少两张！');
			}
			$this->success('保存成功');
		}
	}  
    public function chekmy_info(){
    	if (!M()->autoCheckToken($_POST)){
    		$this->error('禁止外部提交！');
    	}else {
    		$uid=$_SESSION['id'];
			
    		$admin_s['nicheng'] = t(h($_POST['nicheng']));
    		$admin_s['id'] = $uid;
			$admin_s_save=M('admin')->save($admin_s);
			
			$admin_info['uid'] = $uid;
			$admin_info['sex'] = $_POST['sex'];
			$admin_info['year'] = $_POST['year'];
			$admin_info['month'] = $_POST['month'];
			$admin_info['day'] = $_POST['day'];
			$admin_info['home'] = t(h($_POST['home']));
			$admin_info['area'] = t(h($_POST['area']));
			$admin_info['qinggan'] = t(h($_POST['qinggan']));
			$admin_info['qq'] = $_POST['qq'];
			$admin_info['job'] = t(h($_POST['job']));
			$admin_info['education'] = t(h($_POST['education']));
			$admin_info['income'] = t(h($_POST['income']));
			$admin_info['xingqu'] = t(h($_POST['xingqu']));
			
			$admin_info_jiu = M('admin_info')->where("uid=".$uid."")->find();
			//判断是否存在旧资料 开始
			if($admin_info_jiu){
				$admin_info['id'] = $admin_info_jiu['id'];
				$admin_info_save=M('admin_info')->save($admin_info);
				if($admin_info_save){
					$this->assign('jumpUrl', './index.php?a=mycenter_info&m=user');
					$this->success("保存成功！");
				}else{
					$this->error("保存失败！");
				}
			}else {
				$admin_info['state']=1;
				$admin_info['ctime']=time();
				$admin_info_add=M('admin_info')->add($admin_info);
				if( $admin_info_add ){
					$this->assign('jumpUrl', './index.php?a=mycenter_info&m=user');
					$this->success("保存成功！");
				}else {
					$this->error("保存失败！");
				}
			}
			//判断是否存在旧资料 结束
			
    	}
    }
	function getIP() /*获取客户端IP*/  
	{  
		if (@$_SERVER["HTTP_X_FORWARDED_FOR"])  
		$ip = $_SERVER["HTTP_X_FORWARDED_FOR"];  
		else if (@$_SERVER["HTTP_CLIENT_IP"])  
		$ip = $_SERVER["HTTP_CLIENT_IP"];  
		else if (@$_SERVER["REMOTE_ADDR"])  
		$ip = $_SERVER["REMOTE_ADDR"];  
		else if (@getenv("HTTP_X_FORWARDED_FOR"))  
		$ip = getenv("HTTP_X_FORWARDED_FOR");  
		else if (@getenv("HTTP_CLIENT_IP"))  
		$ip = getenv("HTTP_CLIENT_IP");  
		else if (@getenv("REMOTE_ADDR"))  
		$ip = getenv("REMOTE_ADDR");  
		else  
		$ip = "Unknown";  
		return $ip;  
	}    
    public function doart_pl(){
    	if (!M()->autoCheckToken($_POST)){
    		$this->error('禁止外部提交！');
    	}else {
			if(empty($_SESSION['id'])){
				$ip=$this->getIP();
				
				$ip_cunzai=M('admin')->where("ip=".$ip."")->find();
				if($ip_cunzai){
					$_SESSION['id']=$ip_cunzai['id'];
				}else{
					if($ip!="Unknown"){
						$ipattr=explode('.',$ip);
						$youke['nicheng']="游客".$ipattr[0]."***".$ipattr[3];
					}else{
						$youke['nicheng']="游客_未知";
					}
					$youke['ip']="".$ip."";
					$youke['ctime']=time();
					$youke['groupid']=7;
					$youke['state']=1;
					$youke_add=M('admin')->add($youke);
					$_SESSION['id']=$youke_add;
				}
				
				//$group_quan=M('admin_group')->find(7);
				//$_SESSION['admin_quan']=$group_quan['quan'];
				//$pan=$this->pan_quan(15);

			}
			
			$art_pl['uid']=$_SESSION['id'];
			$art_pl['content'] = t(h($_POST['pl_content']));
			$art_pl['artid'] = $_POST['artid'];
			$art_pl['state'] = 1;
			$art_pl['ctime'] = time();
			$art_pl_add=M('article_pl')->add($art_pl);
			
			if( $art_pl_add ){
				$this->success("评论成功！");
			}else {
				$this->error("评论失败！");
			}
			
    	}
    }
    public function doart_pl_hf(){
    	if (!M()->autoCheckToken($_POST)){
    		$this->error('禁止外部提交！');
    	}else {
			if(empty($_SESSION['id'])){
				$ip=$this->getIP();
				
				$ip_cunzai=M('admin')->where("ip=".$ip."")->find();
				if($ip_cunzai){
					$_SESSION['id']=$ip_cunzai['id'];
				}else{
					if($ip!="Unknown"){
						$ipattr=explode('.',$ip);
						$youke['nicheng']="游客".$ipattr[0]."***".$ipattr[3];
					}else{
						$youke['nicheng']="游客_未知";
					}
					$youke['ip']="".$ip."";
					$youke['ctime']=time();
					$youke['groupid']=7;
					$youke['state']=1;
					$youke_add=M('admin')->add($youke);
					$_SESSION['id']=$youke_add;
				}
				
				//$group_quan=M('admin_group')->find(7);
				//$_SESSION['admin_quan']=$group_quan['quan'];
				//$pan=$this->pan_quan(15);

			}
			
			$art_pl['uid']=$_SESSION['id'];
			$art_pl['duid']=$_POST['duid'];
			$art_pl['content'] = t(h($_POST['pl_content']));
			$art_pl['artid'] = $_POST['artid'];
			$art_pl['plid'] = $_POST['plid'];
			$art_pl['state'] = 1;
			$art_pl['ctime'] = time();
			$art_pl_add=M('article_pl')->add($art_pl);
			
			if( $art_pl_add ){
				$this->success("评论成功！");
			}else {
				$this->error("评论失败！");
			}
			
    	}
    }
	public function p_art(){
		$uid=$_SESSION['id'];
		
		import("@.ORG.Page");
		$count	= M('article_pl')->where("uid=".$uid." and plid=0 and state=1")->count();
		$Page	= New Page($count,30);
		$show	= $Page->show();
		$art_pl=M('article_pl')->where("uid=".$uid." and plid=0 and state=1")->order('ctime desc,id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		foreach($art_pl as $k=>$v){
			$art=M('article')->find($v['artid']);
			$art=$this->get_lang($art,"name");
			$art_pl[$k]['art_name']=$art['name'];
			$art_pl[$k]['art_id']=$art['id'];
		}
		$this->assign('art_pl', $art_pl);
		$this->assign('page', $show);
		
		$this->display();
	}
	  
    public function doshop_pl(){
    	if (!M()->autoCheckToken($_POST)){
    		$this->error('禁止外部提交！');
    	}else {
 			if(empty($_SESSION['id'])){
				$ip=$this->getIP();
				
				$ip_cunzai=M('admin')->where("ip=".$ip."")->find();
				if($ip_cunzai){
					$_SESSION['id']=$ip_cunzai['id'];
				}else{
					if($ip!="Unknown"){
						$ipattr=explode('.',$ip);
						$youke['nicheng']="游客".$ipattr[0]."***".$ipattr[3];
					}else{
						$youke['nicheng']="游客_未知";
					}
					$youke['ip']="".$ip."";
					$youke['ctime']=time();
					$youke['groupid']=7;
					$youke['state']=1;
					$youke_add=M('admin')->add($youke);
					$_SESSION['id']=$youke_add;
				}
				
//				$group_quan=M('admin_group')->find(7);
//				$_SESSION['admin_quan']=$group_quan['quan'];
//				$pan=$this->pan_quan(15);
			
			}
			
			$art_pl['uid']=$_SESSION['id'];
			$art_pl['content'] = t(h($_POST['pl_content']));
			$art_pl['artid'] = $_POST['artid'];
			$art_pl['state'] = 1;
			$art_pl['ctime'] = time();
			$art_pl_add=M('shop_pl')->add($art_pl);
			
			if( $art_pl_add ){
				$this->success("评论成功！");
			}else {
				$this->error("评论失败！");
			}
			
    	}
    }
    public function doshop_pl_hf(){
    	if (!M()->autoCheckToken($_POST)){
    		$this->error('禁止外部提交！');
    	}else {
			if(empty($_SESSION['id'])){
				$ip=$this->getIP();
				
				$ip_cunzai=M('admin')->where("ip=".$ip."")->find();
				if($ip_cunzai){
					$_SESSION['id']=$ip_cunzai['id'];
				}else{
					if($ip!="Unknown"){
						$ipattr=explode('.',$ip);
						$youke['nicheng']="游客".$ipattr[0]."***".$ipattr[3];
					}else{
						$youke['nicheng']="游客_未知";
					}
					$youke['ip']="".$ip."";
					$youke['ctime']=time();
					$youke['groupid']=7;
					$youke['state']=1;
					$youke_add=M('admin')->add($youke);
					$_SESSION['id']=$youke_add;
				}
				
				//$group_quan=M('admin_group')->find(7);
				//$_SESSION['admin_quan']=$group_quan['quan'];
				//$pan=$this->pan_quan(15);

			}
			
			$art_pl['uid']=$_SESSION['id'];
			$art_pl['duid']=$_POST['duid'];
			$art_pl['content'] = t(h($_POST['pl_content']));
			$art_pl['artid'] = $_POST['artid'];
			$art_pl['plid'] = $_POST['plid'];
			$art_pl['state'] = 1;
			$art_pl['ctime'] = time();
			$art_pl_add=M('shop_pl')->add($art_pl);
			
			if( $art_pl_add ){
				$this->success("评论成功！");
			}else {
				$this->error("评论失败！");
			}
			
    	}
    }
	 
	public function p_shop(){
		$uid=$_SESSION['id'];
		
		import("@.ORG.Page");
		$count	= M('shop_pl')->where("uid=".$uid." and plid=0 and state=1")->count();
		$Page	= New Page($count,30);
		$show	= $Page->show();
		$art_pl=M('shop_pl')->where("uid=".$uid." and plid=0 and state=1")->order('ctime desc,id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		foreach($art_pl as $k=>$v){
			$art=M('shop')->find($v['artid']);
			$art=$this->get_lang($art,"name");
			$art_pl[$k]['art_name']=$art['name'];
			$art_pl[$k]['art_id']=$art['id'];
		}
		$this->assign('art_pl', $art_pl);
		$this->assign('page', $show);
		
		$this->display();
	}
	//关注文章
	function dogz_art(){
		$artid=$_POST['artid'];
		$uid=$_SESSION['id'];
		$guanzhu['uid']=$uid;
		$guanzhu['artid']=$artid;
		$guanzhu['state']=1;
		$guanzhu['ctime']=time();
		
		
		if(M('article_gz')->where("artid=".$artid." and uid=".$uid." and state=3")->find()){
			if(M('article_gz')->where("artid=".$artid." and uid=".$uid." and state=3")->setField('state','1')){
				M('article')->where("id=".$artid."")->setInc('follows',1);
				echo "1";
			}else{
				echo "0";
			}
		}else{
			if(M('article_gz')->add($guanzhu)){
				M('article')->where("id=".$artid."")->setInc('follows',1);
				echo "1";
			}else{
				echo "0";
			}
		}
		
		exit;
	}
	//取消关注文章
	function doqx_gz_art(){
		$artid=$_POST['artid'];
		$uid=$_SESSION['id'];
		
		if(M('article_gz')->where("artid=".$artid." and uid=".$uid." and state=1")->setField('state','3')){
			M('article')->where("id=".$artid."")->setDec('follows',1);
			echo "1";
		}else{
			echo "0";
		}
		exit;
	}
	  
	   
	//关注文章
	function gz_art(){
		$uid=$_SESSION['id'];
		
		import("@.ORG.Page");
		$count	= M('article_gz')->where("uid=".$uid." and state=1")->count();
		$Page	= New Page($count,30);
		$show	= $Page->show();
		$art_pl=M('article_gz')->where("uid=".$uid." and state=1")->order('ctime desc,id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		foreach($art_pl as $k=>$v){
			$art=M('article')->find($v['artid']);
			$art=$this->get_lang($art,"name");
			$art_pl[$k]['art_name']=$art['name'];
			$art_pl[$k]['art_id']=$art['id'];
		}
		$this->assign('art_pl', $art_pl);
		$this->assign('page', $show);
		
		$this->display();
	}
	//关注商家
	function gz_shop(){
		$uid=$_SESSION['id'];
		
		import("@.ORG.Page");
		$count	= M('shop_gz')->where("uid=".$uid." and state=1")->count();
		$Page	= New Page($count,30);
		$show	= $Page->show();
		$art_pl=M('shop_gz')->where("uid=".$uid." and state=1")->order('ctime desc,id desc')->limit($Page->firstRow.','.$Page->listRows)->select();
		foreach($art_pl as $k=>$v){
			$art=M('shop')->find($v['artid']);
			$art=$this->get_lang($art,"name");
			$art_pl[$k]['art_name']=$art['name'];
			$art_pl[$k]['art_id']=$art['id'];
		}
		$this->assign('art_pl', $art_pl);
		$this->assign('page', $show);
		
		$this->display();
	}
	//关注商家
	function dogz_shop(){
		$artid=$_POST['artid'];
		$uid=$_SESSION['id'];
		$guanzhu['uid']=$uid;
		$guanzhu['artid']=$artid;
		$guanzhu['state']=1;
		$guanzhu['ctime']=time();
		
		if(M('shop_gz')->where("artid=".$artid." and uid=".$uid." and state=3")->find()){
			if(M('shop_gz')->where("artid=".$artid." and uid=".$uid." and state=3")->setField('state','1')){
				M('shop')->where("id=".$artid."")->setInc('follows',1);
				echo "1";
			}else{
				echo "0";
			}
		}else{
			if(M('shop_gz')->add($guanzhu)){
				M('shop')->where("id=".$artid."")->setInc('follows',1);
				echo "1";
			}else{
				echo "0";
			}
		}
		exit;
	}
	//取消关注商家
	function doqx_gz_shop(){
		$artid=$_POST['artid'];
		$uid=$_SESSION['id'];
		
		if(M('shop_gz')->where("artid=".$artid." and uid=".$uid." and state=1")->setField('state','3')){
			M('shop')->where("id=".$artid."")->setDec('follows',1);
			echo "1";
		}else{
			echo "0";
		}
		exit;
	}
	//修改密码
	function g_pwd(){
		$uid=$_SESSION['uid'];
				
		$this->display();
	}
	//修改密码
	function dog_pwd(){
		$uid=$_SESSION['id'];
	
	    if(!M()->autoCheckToken($_POST)) $this->error('非法提交');
		unset($_POST['__hash__']);
		
		$pass_jiu=md5($_POST['pass_jiu']);
		//var_dump($uid);exit;
		$yz_pass_jiu=M('admin')->find($uid);
		if($yz_pass_jiu['passwd']==$pass_jiu){
			if($_POST['pass'] != '' ){
				if( strlen($_POST['pass']) < 6) $this->error('密码过短！');
				if($_POST['pass'] != $_POST['pass2']) $this->error('您两次输入的密码不一致');
				$map['passwd'] = md5( $_POST['pass'] );
			}
			
			$map['id'] = $uid;
			if(M('admin')->save($map)){
			$this->assign('jumpUrl',U('User/g_pwd'));
			$this->success('修改成功！');
			}else $this->error('和原密码一样！');
	
		}else{
			$this->error('原密码错误！');
		}
				
	}
	//删除评论、关注等
	function del_pl(){//删除
//		$pan_admin=$this->pan_quan_ajax(3);//判断权限
//		if(!$pan_admin){
//			echo '0';exit;
//		}
	    $ids = $_POST['ids'];
	    $sql_m = $_POST['sql_m'];
		$del = M("".$sql_m."")->where("id IN ($ids)")->setField('state','3');//3为已删除
        echo $del?'1':'0';
	}
	  
	function setsessionlog(){//删除
	    $id=intval($_GET['id']);
		$passwd=t(h($_GET['jm']));
		$res=M("admin")->where("id=".$id." ")->find();

		if($res['state']==1 && $res['passwd']==$passwd){
			setcookie('id', $res['id'], time()+60*60*24);
			setcookie('id', $res['id'], time()+60*60*24,"/","mxingtv.com",0);
		}
		
		echo $res['id'];
	}
	function clearsessionlog(){//删除
		
		setcookie('id', 0, time());
		setcookie('id', 0, time(), "/", "mxingtv.com",0);
		//echo $res['id'];
	}
	//用户列表
	function users(){
		
		import("@.ORG.Page");
		$count	= M('user')->where("state=1")->count();
		$Page	= New Page($count,15);
		$show	= $Page->show();
		
		$pid=t(h($_GET['pid']));
		if($pid==1){
			$users=M('user')->where("state=1")->order("fensinum desc,id desc")->limit($Page->firstRow.','.$Page->listRows)->select();
		}else{
			$users=M('user')->where("state=1")->order("ctime desc,id desc")->limit($Page->firstRow.','.$Page->listRows)->select();
		}
		$this->assign('nowPage',$Page->nowPage);
		$this->assign('pid',$pid);
		$this->assign('users',$users);
		$this->assign('page', $show);
		$this->display();
	}
	  
	//用户主页
	function user(){
		//$webid=$this->get_webid();
		$show_uid=$_GET['suid'];
		$user_show=M('user')->find($show_uid);
		$user_groupname=M('user_group')->find($user_show['groupid']);
		$user_show['groupname']=$user_groupname['name'];
		$this->assign('user_show',$user_show);
		$user_show_info=M('user_info')->where("uid=".$show_uid."")->find();
		$year=date('Y',time());
		if($user_show_info['year']<=0 || $user_show_info['year']>$year){
			$user_show_info['old']=0;
		}else{
			$user_show_info['old']=$year-$user_show_info['year'];
		}
		$this->assign('user_show_info',$user_show_info);
		$user_show_videos=M('videos')->where("zhuboid=".$show_uid." and state=1")->order('ctime desc,id desc')->select();
		$this->assign('user_show_videos',$user_show_videos);
		$user_show_photo_files=M('article_photo_files')->where("suid=".$show_uid." and state=1")->order('ctime desc,id desc')->select();
		$this->assign('user_show_photo_files',$user_show_photo_files);
		$user_fensi=M('user_fensi')->where("uid=".$_COOKIE['id']." and ftouid=".$show_uid."")->find();
		$this->assign('user_fensi',$user_fensi);
		$this->display();
	}
	//萌主播报名页
	function baoming(){
		$uid=$_SESSION['id'];
		if(empty($uid)){
			$this->error('请先登录');
		}
		$sf_yi_baoming=M("user_baoming")->where("uid=".$uid." and state=1")->find();
		if(!empty($sf_yi_baoming)){
			$this->error('已报名');
		}
		//$webid=$this->get_webid();
		//$show_uid=$_GET['suid'];
		
		$user_show=M('user')->where("id=".$uid."")->find();
		$this->assign('user_show',$user_show);
		
		$user_show_info=M('user_info')->where("uid=".$uid."")->find();
		$this->assign('user_show_info',$user_show_info);
		$photo_file=M("article_photo_files")->where("suid=".$uid." and state=1")->find();
		$user_photo=M('article_photo')->where("suid=".$uid." and fid=".$photo_file['id']." and state=1")->select();
		$this->assign('user_photo',$user_photo);

		$this->display();
	}
	function tofensi(){
		$uid=$_SESSION['id'];
		$ftouid=$_POST['tuid'];
		$ftovid=$_POST['tvid'];
		if(!empty($uid)){
			$data['state']=1;
			$data['ctime']=time();
			$data['ip']=$this->getIP();
			$data['uid']=$uid;
			
			if($ftouid>0){
				$data['ftouid']=$ftouid;
				$fensi_jiu=M('user_fensi')->where("uid=".$uid." and ftouid=".$ftouid."")->find();
				if(empty($fensi_jiu)){
					$addfensi=M('user_fensi')->add($data);
					if($addfensi){
						M('user')->where("id=".$ftouid."")->setInc('fensinum');
						echo $addfensi;
					}
				}else{
					echo -2;
				}
			}else{
				$data['ftovid']=$ftovid;
				$fensi_jiu=M('user_fensi')->where("uid=".$uid." and ftovid=".$ftovid."")->find();
				if(empty($fensi_jiu)){
					$addfensi=M('user_fensi')->add($data);
					if($addfensi){
						M('videos')->where("id=".$ftovid."")->setInc('zannum');
						echo $addfensi;
					}
				}else{
					echo -2;
				}
			}
		}else{
			echo -1;
		}
		exit;
	}  
	function getlogzt(){
		$uid=$_SESSION['id'];
		if(!empty($uid)){
			echo 1;
		}else{
			echo 0;
		}
		exit;
	}  
	function upload_img_php(){
	
		if(''==$_POST['name']){
    		$this->error('请填写姓名！');
    	}elseif (''==$_POST['yiming']){
    		$this->error('请填写艺名！');
    	}elseif (''==$_POST['sex']){
    		$this->error('请选择性别！');
    	}elseif (''==$_POST['year'] || ''==$_POST['month'] || ''==$_POST['day']){
    		$this->error('请选择出生日期！');
    	}elseif (''==$_POST['minzu']){
    		$this->error('请填写民族！');
    	}elseif (''==$_POST['shengao']){
    		$this->error('请填写身高！');
    	}elseif (''==$_POST['tizhong']){
    		$this->error('请填写体重！');
    	}elseif (''==$_POST['xingzuo']){
    		$this->error('请选择星座！');
    	}elseif (''==$_POST['yuyan']){
    		$this->error('请填写语言！');
    	}elseif (''==$_POST['home']){
    		$this->error('请填写籍贯！');
    	}elseif (''==$_POST['area']){
    		$this->error('请填写现居住地！');
    	}elseif (''==$_POST['email']){
    		$this->error('请填写邮箱！');
    	}elseif (''==$_POST['tel']){
    		$this->error('请填写手机号！');
    	}elseif (''==$_POST['xingqu']){
    		$this->error('请填写特长爱好！');
    	}elseif (''==$_POST['jianjie']){
    		$this->error('请填写主播宣言！');
    	}else {
			
			if(empty($_SESSION['id'])){
				$this->error('请先登录！');
			}
			$uid=$_SESSION['id'];
			$sf_yi_baoming=M("user_baoming")->where("uid=".$uid." and state=1")->find();
 			if(!empty($sf_yi_baoming)){
				$this->error('已报名');
			}
   		
			$user_show['id']=$uid;
			$user_show['name']=t(h($_POST['name']));
			$user_show['email']=t(h($_POST['email']));
			$user_show['tel']=t(h($_POST['tel']));
			
			$user_show_info['uid']=$uid;
			$user_show_info['yiming']=t(h($_POST['yiming']));
			$user_show_info['sex']=t(h($_POST['sex']));
			$user_show_info['year']=t(h($_POST['year']));
			$user_show_info['month']=t(h($_POST['month']));
			$user_show_info['day']=t(h($_POST['day']));
			$user_show_info['minzu']=t(h($_POST['minzu']));
			$user_show_info['shengao']=t(h($_POST['shengao']));
			$user_show_info['tizhong']=t(h($_POST['tizhong']));
			$user_show_info['xingzuo']=t(h($_POST['xingzuo']));
			$user_show_info['yuyan']=t(h($_POST['yuyan']));
			$user_show_info['home']=t(h($_POST['home']));
			$user_show_info['area']=t(h($_POST['area']));
			$user_show_info['xingqu']=t(h($_POST['xingqu']));
			$user_show_info['jianjie']=t(h($_POST['jianjie']));
			$user_show_info['peixun']=t(h($_POST['peixun']));
			$user_show_info['guhua']=t(h($_POST['guhua']));
			$user_show_info['ctime']=time();
			$user_show_info['state']=1;
			
			M("user")->save($user_show);
			
			$user_show_info_jiu=M("user_info")->where("uid=".$uid."")->find();
			if(empty($user_show_info_jiu)){
				M("user_info")->add($user_show_info);
			}else{
				$user_show_info['id']=$user_show_info_jiu['id'];
				M("user_info")->save($user_show_info);
			}

			$folder="/data/baomingxiezhen/";
			for ($i=0;$i<count($_FILES);$i++) 
			{ 
				if(!empty($_FILES[$i]['name'])){
					$picname = $_FILES[$i]['name'];
					$picsize = $_FILES[$i]['size'];
					if ($picname != "") {
						if ($picsize > 2048000) {
							echo '图片大小不能超过2M';
							exit;
						}
						$type = strstr($picname, '.');
						if ( $type != ".jpg") {
							echo '图片格式不对！';
							exit;
						}
						$rand = rand(1000, 9999);
						$pics = date("YmdHis",time()) . "_".$rand . $type;
						//上传路径
						$targetPath = $_SERVER['DOCUMENT_ROOT'] . $folder;
						$pic_path =  str_replace('//','/',$targetPath) . $pics;
						//mkdir(str_replace('//','/',$targetPath), 0755, true);
						if(!is_dir(str_replace('//','/',$targetPath))){
							mkdir(str_replace('//','/',$targetPath), 0755, true); //创建 目录
						}
				
						move_uploaded_file($_FILES[$i]['tmp_name'], $pic_path);
					}
					$size = round($picsize/2048,2);
					$arr[$i] = array(
						'name'=>$picname,
						'pic'=>$pics,
						'pic_path'=>$folder.$pics,
						'size'=>$size
					);
					
					$photo['name']="写真照".($i+1);
					$photo['url']=$folder.$pics;
					$photo['state']=1;
					$photo['ctime']=time();
					$photo['suid']=$uid;
					$photo['uid']=$uid;
						
					$photo_file=M("article_photo_files")->where("suid=".$uid." and state=1")->find();
					if(!empty($photo_file)){
						$photo['fid']=$photo_file['id'];
						M("article_photo")->add($photo);
					}else{
						$new_photo_file['uid']=$uid;
						$new_photo_file['suid']=$uid;
						$new_photo_file['state']=1;
						$new_photo_file['ctime']=time();
						$new_photo_file['name']="写真集";
						$new_photo_file['url']=$folder.$pics;
						$new_files=M("article_photo_files")->add($new_photo_file);
						
						$photo['fid']=$new_files;
						M("article_photo")->add($photo);
					}
				}
			} 
			$photo_file_jiu=M("article_photo_files")->where("suid=".$uid." and state=1")->find();
			$photo_jiu=M("article_photo")->where("suid=".$uid." and fid=".$photo_file_jiu['id']." and state=1")->select();
			if(count($arr)<2 && count($photo_jiu)==0){
				$this->error('照片最少两张！');
			}
			if(count($arr)<1 && count($photo_jiu)==1){
				$this->error('照片最少两张！');
			}
//for ($i=0;$i<count($_FILES['mypic']['tmp_name']);$i++) 
//{ 
//	$picname=$folder."/".$_FILES['mypic']['name'][$i];//此处可以根据自己的需要修改 
//	if(move_uploaded_file($_FILES['mypic']['tmp_name'][$i],$picname)){ 
//		echo "第".($i+1)."张图片上传成功<br>"; 
//	} 
//	else{ 
//		echo "第".($i+1)."张图片上传不了<br>"; 
//	} 
//} 
		//include_once("/Public/js/upload_share/image.php");
		//$folder="/data/baomingxiezhen/";
		//$picname=$_POST['mypic'];
//		$picname=$_FILES['mypic']['name'];
//		$picsize = $_FILES['mypic']['size'];
//		if ($picname != "") {
//			if ($picsize > 2048000) {
//				echo '图片大小不能超过2M';
//				exit;
//			}
//			$type = strstr($picname, '.');
//			if ( $type != ".jpg") {
//				echo '图片格式不对！';
//				exit;
//			}
//			$rand = rand(1000, 9999);
//			$pics = date("YmdHis",time()) . "_".$rand . $type;
//			//上传路径
//			$targetPath = $_SERVER['DOCUMENT_ROOT'] . $folder;
//			$pic_path =  str_replace('//','/',$targetPath) . $pics;
//			//mkdir(str_replace('//','/',$targetPath), 0755, true);
//			if(!is_dir(str_replace('//','/',$targetPath))){
//				mkdir(str_replace('//','/',$targetPath), 0755, true); //创建 目录
//			}
//	
//			move_uploaded_file($_FILES['mypic']['tmp_name'], $pic_path);
//			//水印地址
//			//$water = 'watercs003.gif';
//			//$img = new image();
//			
//			//$img->param($targetFile)->water($targetFile,$water,9);
//			//$img->param($targetFile)->water($targetFile,$water,9);
//			
//			//生成缩略图
//	//		if(!is_dir(str_replace('//','/',$targetPath).'thumb/')){
//	//			mkdir(str_replace('//','/',$targetPath).'thumb/', 0755, true); //创建 thumb 目录
//	//		}
//	//		$thumb_url=str_replace('//','/',$targetPath).'thumb/'.$pics;
//	//		$img->param($pic_path)->thumb($thumb_url,500,500,0,0);
//		}
//		$size = round($picsize/2048,2);
//		$arr = array(
//			'name'=>$picname,
//			'pic'=>$pics,
//			'pic_path'=>$folder.$pics,
//			'size'=>$size
//		);
		//echo json_encode($arr);
		/*echo "<script>alert('上传成功');history.go(-1);</script>";*/
		//$this->error('上传成功');
			
			$new_baoming['uid']=$uid;
			$new_baoming['ctime']=time();
			$new_baoming['state']=1;
			M("user_baoming")->add($new_baoming);
			
			$this->assign('jumpUrl', U('User/mycenter'));
			$this->success('报名成功');
		}
	}  
	  
	//微信登录相关
    function loginbyweixin(){
//		if(empty($_COOKIE['ly_url'])){
//			if(!empty($_SERVER['HTTP_REFERER'])){
//				$ly_url=$_SERVER['HTTP_REFERER'];
//			}else{
//				$ly_url="./index.php";
//			}
//			setcookie('ly_url',$ly_url);
//		}
		if($_SESSION['id']>0){
			//$this->assign('jumpUrl',U('User/mycenter'));
			$this->assign('jumpUrl',U('User/mycenter'));
			$this->error("已登录！");
		}else{
		
			$user_agent = $_SERVER['HTTP_USER_AGENT'];
			//var_dump(strpos($user_agent, 'MicroMessenger'));
			if (strpos($user_agent, 'MicroMessenger') === false) {
				// 非微信浏览器禁止浏览
				//echo "HTTP/1.1 401 Unauthorized";
			} else {
				if($_SESSION['wx_bzh']!=4){
					$appid = "wx7f89dee3f9bd4117";

					$url="https://open.weixin.qq.com/connect/oauth2/authorize?appid=".$appid."&redirect_uri=http%3a%2f%2fwww.mxingtv.com%2findex.php%3fa%3dwx_login%26m%3duser&response_type=code&scope=snsapi_userinfo&state=type";

					echo "<script language='javascript' type='text/javascript'>";  
					echo "window.location.href='$url'";  
					echo "</script>";
					exit;
				}
			}

			$this->assign('jumpUrl', './index.php?a=mycenter&m=user');
			$this->error("授权错误！");
			
			
//			$this->assign('pagetitle', '欢迎登录');
//			$this->display();
		}
    }
	function get_user_info($openid)
    {
        $url = "https://api.weixin.qq.com/sns/userinfo?access_token=".$this->access_token."&openid=".$openid."&lang=zh_CN";
        $res = $this->https_request($url);
        return json_decode($res, true);
    }
	function https_request($url, $data = null)//微信登录https请求
    {
        $curl = curl_init();
        curl_setopt($curl, CURLOPT_URL, $url);
        curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE);
        curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
        if (!empty($data)){
            curl_setopt($curl, CURLOPT_POST, 1);
            curl_setopt($curl, CURLOPT_POSTFIELDS, $data);
        }
        curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
        $output = curl_exec($curl);
        curl_close($curl);
        return $output;
    } 
	function wx_login(){//微信登录
		
		$appid = "wx7f89dee3f9bd4117";
    	$appsecret = "f7903906e8430e4832c559bfba90e417";
		
//		$this->lasttime = $_SESSION['wx_lasttime'];
//        $this->access_token = "nRZvVpDU7LxcSi7GnG2LrUcmKbAECzRf0NyDBwKlng4nMPf88d34pkzdNcvhqm4clidLGAS18cN1RTSK60p49zIZY4aO13sF-eqsCs0xjlbad-lKVskk8T7gALQ5dIrgXbQQ_TAesSasjJ210vIqTQ";
//
//        if (time() > ($this->lasttime + 7200)){
//            $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".$appid."&secret=".$appsecret;
//            $res = $this->https_request($url);
//            $result = json_decode($res, true);
//            
//            $this->access_token = $result["access_token"];
//			$_SESSION['wx_lasttime']=time();
//            $this->lasttime = time();
//        }
		if (isset($_GET['code'])){
			$url="https://api.weixin.qq.com/sns/oauth2/access_token?appid=".$appid."&secret=".$appsecret."&code=".$_GET['code']."&grant_type=authorization_code";
			$res = $this->https_request($url);
			$res=(json_decode($res, true));
			
			$this->access_token = $res["access_token"];
			
			$row=$this->get_user_info($res['openid']);
			
			if ($row['openid']) {
				//这里写上逻辑,存入cookie,数据库等操作
				$user['wx_openid']=$row['openid'];
				$user['nicheng']=$row['nickname'];
				$user['touxiang']=$row['headimgurl'];
				$user['wx_unionid']=$row['unionid'];
				
				$user_info['sex']=$row['sex'];
				$user_info['area']=$row['province'].$row['city'];
				
				$user_jiu=M('user')->where("wx_unionid='".$user['wx_unionid']."'")->find();
				
				if(!empty($user_jiu)){
					if(empty($user_jiu['wx_openid'])){
						$user_jiu['wx_openid']=$row['openid'];
						$user_jiu['wx_unionid']=$row['unionid'];
						M('user')->save($user_jiu);
					}
					$_SESSION['id']=$user_jiu['id'];
				}else{
					$user['groupid']=1;
					$user['state']=1;
					$user['ctime']=time();
					$user_new=M('admin')->add($user);
					$_SESSION['id']=$user_new;
				}
							
				$_SESSION['wx_bzh']=4;

				$this->assign('waitSecond', 0);
				$this->assign('jumpUrl',U('User/mycenter'));
				$this->success("{$_SESSION['nicheng']}登录成功！");
			
			}else{
				$this->error('授权出错,请重新授权!');
			}

		}else{
			
//			$url = "https://open.weixin.qq.com/connect/qrconnect?appid=".$appid."&redirect_uri=http%3a%2f%2fwww.4into.com%2findex.php%3fa%3dwx_login%26m%3duser&response_type=code&scope=snsapi_login";
//			$res = $this->https_request($url);
//			$result = json_decode($res, true);
		}
		
	}
	 
	
} 
